home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
364_01
/
intf_ca.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-24
|
19KB
|
787 lines
/*
HEADER: ;
TITLE: C-ACROSS;
VERSION 1.02
DESCRIPTION: "Utility for multiple module programs. Produces
Six indexes of functions, prototypes, and globals that
enable user to 'see across' modules for use in checking
and comparison. One of these is type of hierarchical
functions list, a listing by module of functions
and calls made FROM them; another is alphabetical list
of functions and calls made TO them. Globals listed
in schematic descriptors which record all modifiers
and qualifiers and enable checking of declarators
across modules. Creates, on request, header file
consisting of prototypes constructed from function
definitions. Can list user types #defined and some
preprocessor #defines. Full documentation in README.CA";
KEYWORDS: Utility, Cross Reference, Deubgging;
SYSTEM: MS-DOS;
FILENAME: INTF_CA.C;
WARNINGS: "1. Assumes function definitions conform with
ANSI standards and have prototype form. See
also "Caveats and Restrictions" in README.CA.
2. Assumes syntactically correct source files.
3. Written and tested using Microsoft QuickC.
4. Copyright retained. See Copyright
information in README.CA.";
SEE-ALSO: EXIT_CA.C, FUNC_CA.C, GLOB_CA.C, IFDEF_CA.C, INTF_CA.C,
LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
UTLG_CA.C, XRF_CA.C, README.CA,
CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
AUTHORS: Myron Turner;
COMPILERS: Microsoft C;
*/
/*************************** C-ACROSS ***************************
V. 1.02
Copyright (C) Myron Turner
333 Bartlet Ave.
Winnipeg, Manitoba
Canada R3L 0Z9
(204) 284-8387
*********************************************************************/
#include <stdio.h>
#include <string.h>
#include <graph.h>
#include <malloc.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <direct.h>
#include <errno.h>
#define EXIT_CODES
#include "ca.h"
#include "ca_decl.h"
#define WHITE 0x7
#define INTENSE 0x8
#define HIGH_VIDEO _settextcolor(WHITE | INTENSE)
#define LOW_VIDEO _settextcolor(WHITE)
/* general externs and globals */
extern struct globals_list *globals_start;
char rpt_fname[_MAX_FNAME] = "\0\0";
char *CurrentMod = NULL;
struct rccoord locate;
/* Globals for Command Line Options */
int __Inclf_Limit = 5;
char NewInclude[128]="INCLUDE=\0\0";
FILE *scrn_out = (FILE *)stdout;
int declare_file = 0;
int user_hf_VAR = 0;
int user_hf_FUNC = 0;
int user_hfile_only = 0;
int verbose = 0;
size_t GLfpSsize = 15;
static SplitNumber_rpf = 0;
int IfDefOFF = 0;
int __Complex_Declarators = 1;
int __Complex_Prototypes = 1;
void ini_characterset(void);
/** NOTE: Command Line and Makefile filespecs are limited to 63 characters**/
/**This is set by FILENAME_MAX in STDIO.H**/
int switches_found = 0;
void main(int argc, char **argv)
{
struct filespec *c_file_start = NULL;
struct func *func_start;
FILE *rptfp;
char *file_string = NULL;
int prj = 0;
_clearscreen(0);
if (argc > 1) {
file_string = argv_cat(argc, argv);
if (*file_string == '@') {
prj = 1;
file_string = readmakefile(file_string);
}
if (file_string)
c_file_start = extract_file_names(file_string);
else {
int c;
printf("\nMake file not found. Continue [Y/N]?\n");
c = getch();
if (c != 'y' || c != 'Y') exit(0);
}
}
if (!file_string || (!c_file_start && switches_found))
c_file_start = get_modules();
if (!c_file_start)
if (file_string && prj) exit_ca (BAD_PROJ, "");
if (!c_file_start) exit_ca (NO_FILE_STR, "");
rptfp = make_rptfile(c_file_start->path);
ini_characterset();
loop_through_modules (c_file_start, &func_start, rptfp);
if (declare_file) { fcloseall(); exit(0); }
print_ll(func_start, rptfp);
if(SplitNumber_rpf == 3)
rptfp = open_reportfile(FIRST_SPLIT);
xrf(func_start, c_file_start, rptfp);
if(SplitNumber_rpf == 2)
rptfp = open_reportfile(FIRST_SPLIT);
print_calls_from(func_start, rptfp);
print_fnptrs(func_start,rptfp);
if(SplitNumber_rpf == 3)
rptfp = open_reportfile(SECOND_SPLIT);
print_alphab_globals(globals_start, rptfp);
fcloseall();
}
/*lint -epu */
struct filespec *get_modules(void)
{
char *file_string, buffer[81];
size_t strL;
int ampersand;
instructions();
if ( !( file_string = (char *) malloc(sizeof (char) * 81 ) ) )return NULL;
*buffer = '\0';
*file_string = '\0';
do
{
relocate();
HIGH_VIDEO;
_outtext("C Files: ");
LOW_VIDEO;
fgets (buffer, 80, stdin);
if (*buffer == '\n') exit(0);
strupr( buffer );
strL = strlen(buffer);
strncat (file_string, buffer, strL - (size_t) 1);
strL = strlen(file_string);
ampersand = reallocate(file_string, strL);
} while (ampersand);
return ( extract_file_names(file_string));
}
struct filespec *extract_file_names(char *file_string)
{
char seps[] = " +";
struct filespec *c_file_ptr, *previous, *c_file_start = NULL;
if ( !(
c_file_ptr = (struct filespec *)
malloc ((size_t) sizeof (struct filespec) )
) ) return (NULL);
if (!c_file_start) c_file_start = c_file_ptr;
c_file_ptr->next = NULL;
c_file_ptr->path = strtok( file_string, seps ); /* Find first token */
if (!c_file_ptr->path) return (NULL);
if (c_file_ptr->path)
if(*c_file_ptr->path == '&') return (NULL);
while( c_file_ptr->path != NULL )
{
previous = c_file_ptr;
if ( !(
c_file_ptr = (struct filespec *)
malloc ((size_t) sizeof (struct filespec) )
) ) return (NULL);
c_file_ptr->next = NULL;
previous->next = c_file_ptr;
c_file_ptr->path = strtok( NULL, seps ); /* Find next token */
}
if (c_file_start) return c_file_start;
return (NULL);
}
void instructions (void)
{
_clearscreen(0);
HIGH_VIDEO;
_outtext("\nInstructions: \n");
LOW_VIDEO;
printf(
"Enter C files, separated by spaces or commas; if the files need more than\n"
"one line, append an & to end of line and continue on to next line (do the\n"
"same for each new line needed). The \'.C\' extension is assumed. [Note: it\n"
"is also assumed that each new function begins on a new line and that\n"
"function declarations conform to new ANSI style.]\n\n"
);
relocate();
}
static int reallocate(char *file_string, size_t strL)
{
int count;
static int line = 1;
char *p;
for (p = file_string + (int) strL - 1, count = (int) strL;
count; count--, p++)
if (*p != ' ') break;
strL = count;
count--;
if (file_string[count] == '&') {
if (file_string[count - 1] != ' ') return(0);
}
else return(0);
file_string[count] = ' ';
line++;
file_string = realloc(file_string, (strL + 81) * sizeof(char));
file_string[strL] = '\0';
return (1);
}
void loop_through_modules (struct filespec *top, struct func **func_start,
FILE *rptfp)
{
char fname[_MAX_FNAME];
FILE *fp;
struct func *start = NULL, *current_func = NULL;
if (!top) return;
if (!declare_file) print_headings(0, rptfp );
while (top->path)
{
do
{
strcpy(fname, top->path);
fp = open_c_file(fname, rptfp);
if (!fp) get_new_path(top);
}
while (!fp);
user_hfile_only = user_hf_FUNC;
start = main_loop(fp, rptfp, fname);
CurrentMod = fname;
user_hfile_only = user_hf_VAR;
if (!declare_file)
current_func = record_variables(fp, rptfp, current_func, &start);
fclose(fp);
top = top->next;
}
*func_start = start; /* func_start = start of alphabetical linked list */
}
int paginate(FILE *rptfp)
{
static int line_count = 0;
static int page = 2;
char dash = '-';
if(declare_file) return (0);
line_count++;
if (line_count > 59)
{
fprintf(rptfp, "\f\n%38c%d-\n\n",dash, page);
line_count = 4;
heading(rptfp, rpt_fname);
page++;
return(0);